#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTreeWidgetItem>
#include <QListWidgetItem>

#include "nullptr.h"
#include "tinyXML/tinyxml.h"
#include "Metamorphosis/Generated/Configuration.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    
private slots:
    void on_treeWidget_customContextMenuRequested(const QPoint &pos);

    void addCategoryHandler();
    void editCategoryHandler();
    void deleteCategoryHandler();

    void addItemHandler();
    void editItemHandler();
    void deleteItemHandler();

    void cutItemHandler();
    void copyItemHandler();
    void pasteItemHandler();


    void on_listWidget_customContextMenuRequested(const QPoint &pos);

    void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);

    void on_actionExit_triggered();

    void on_actionAbout_triggered();

    void on_listWidget_itemChanged(QListWidgetItem *item);

    void on_treeWidget_itemChanged(QTreeWidgetItem *item, int column);

    void on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);

    void on_actionOpen_project_triggered();

    void on_actionSave_project_triggered();

    void on_actionSave_Project_As_triggered();

    void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);

    void on_listWidget_itemDoubleClicked(QListWidgetItem *item);

private:
    Ui::MainWindow *ui;
    QAction *actionAddCategory;
    QAction *actionEditCategory;
    QAction *actionDeleteCategory;
    QAction *actionAddItem;
    QAction *actionEditItem;
    QAction *actionDeleteItem;
    QAction *actionCopyItem;
    QAction *actionCutItem;
    QAction *actionPasteItem;
    void setupActions();
    void configureCategoryActions();
    void configureItemActions();
    void reloadItems(QListWidget& list);
    void reloadItems(yasa::configuration::ISTCategory& category, const std::vector<struct yasa::configuration::ISTItem>& items, QListWidget& list);
    void reloadTree(QTreeWidget &tree, QTreeWidgetItem *node, const yasa::configuration::ISTCategory &item);
    void reloadTree(QTreeWidget &tree);
    void saveConfig();
};

#endif // MAINWINDOW_H
